/**
 * <copyright> 
 *
 * Copyright (c) 2008 itemis AG and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   itemis AG - Initial API and implementation
 *
 * </copyright>
 *
 */
package com.rd.emf.geneditor.model;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * @author Dennis Huebner
 * 
 */
public class OawFacade {

	public static final String CHECK_EXT = "Checks";
	public static final String STYLE_EXT = "ItemLabelProvider";
	public static final String PROPOSAL_EXT = "Proposals";

	public OawFacade() {
	}

	public Object style(String extension, EObject object) {
		String extendFile = path(object) + OawFacade.STYLE_EXT;
		Object retVal = evaluate(extendFile, extension, object);
		return retVal;
	}

	/**
	 * @param extensionFile
	 * @param extensionName
	 * @param params
	 * @return
	 */
	private Object evaluate(String extensionFile, String extensionName, Object... params) {
		Object retVal = null;

		return retVal;
	}

	// TODO split method
	public List<?> proposals(EStructuralFeature feature, EObject ctx, List<?> fromList) {
		String extFile = path(ctx) + OawFacade.PROPOSAL_EXT;
		List<?> retVal = new ArrayList<Object>();
		Object eval;
		if (fromList != null) {
			retVal = fromList;
			eval = evaluate(extFile, feature.getName(), ctx, fromList);
		} else {
			eval = evaluate(extFile, feature.getName(), ctx);
		}
		if (eval != null) {
			if (eval instanceof List<?>) {
				retVal = (List<?>) eval;
			} else {
				com.rd.emf.geneditor.EMFGenericEditorPlugin.logError("Returned type must be a List! File:" + extFile
						+ ", Extension:" + feature.getName());
			}
		}
		return retVal;
	}

	private String path(EObject object) {
		return object.eClass().getEPackage().getName() + "//";
	}

}
